<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns or sets the AUTOCOMMIT state for a database connection</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.db2-autocommit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_autocommit</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_autocommit</span> &mdash; <span class="dc-title">
   Returns or sets the AUTOCOMMIT state for a database connection
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.db2-autocommit-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>db2_autocommit</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$value</code></span>
  ] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>


  <p class="para rdfs-comment">
   Sets or gets the AUTOCOMMIT behavior of the specified connection resource.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.db2-autocommit-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">connection</code></dt>

     <dd>

      <p class="para">
       A valid database connection resource variable as returned from
       <span class="function"><a href="db2_connect.html" class="function">db2_connect()</a></span> or <span class="function"><a href="db2_pconnect.html" class="function">db2_pconnect()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       One of the following constants: 
       <dl>

        
         <dt>
<em>DB2_AUTOCOMMIT_OFF</em></dt>

         <dd>

          <p class="para">
           Turns AUTOCOMMIT off.
          </p>
         </dd>

        
        
         <dt>
<em>DB2_AUTOCOMMIT_ON</em></dt>

         <dd>

          <p class="para">
           Turns AUTOCOMMIT on.
          </p>
         </dd>

        
       </dl>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.db2-autocommit-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   When <span class="function"><strong>db2_autocommit()</strong></span> receives only the
   <code class="parameter">connection</code> parameter, it returns the current state
   of AUTOCOMMIT for the requested connection as an integer value. A value of
   0 indicates that AUTOCOMMIT is off, while a value of 1 indicates that
   AUTOCOMMIT is on.
  </p>
  <p class="para">
   When <span class="function"><strong>db2_autocommit()</strong></span> receives both the
   <code class="parameter">connection</code> parameter and
   <code class="parameter">autocommit</code> parameter, it attempts to set the
   AUTOCOMMIT state of the requested connection to the corresponding state.
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.db2-autocommit-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1228">
    <p><strong>Example #1 Retrieving the AUTOCOMMIT value for a connection</strong></p>
    <div class="example-contents"><p>
     In the following example, a connection which has been created with
     AUTOCOMMIT turned off is tested with the
     <span class="function"><strong>db2_autocommit()</strong></span> function.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ac&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$ac&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$ac</span><span style="color: #DD0000">&nbsp;--&nbsp;AUTOCOMMIT&nbsp;is&nbsp;off."</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$ac</span><span style="color: #DD0000">&nbsp;--&nbsp;AUTOCOMMIT&nbsp;is&nbsp;on."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
0 -- AUTOCOMMIT is off.
</pre></div>
    </div>
   </div>
   <div class="example" id="example-1229">
    <p><strong>Example #2 Setting the AUTOCOMMIT value for a connection</strong></p>
    <div class="example-contents"><p>
     In the following example, a connection which was initially created with
     AUTOCOMMIT turned off has its behavior changed to turn AUTOCOMMIT on.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Turn&nbsp;AUTOCOMMIT&nbsp;on<br /></span><span style="color: #0000BB">$rc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_ON</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$rc</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Turning&nbsp;AUTOCOMMIT&nbsp;on&nbsp;succeeded.\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Check&nbsp;AUTOCOMMIT&nbsp;state<br /></span><span style="color: #0000BB">$ac&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$ac&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$ac</span><span style="color: #DD0000">&nbsp;--&nbsp;AUTOCOMMIT&nbsp;is&nbsp;off."</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$ac</span><span style="color: #DD0000">&nbsp;--&nbsp;AUTOCOMMIT&nbsp;is&nbsp;on."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Turning AUTOCOMMIT on succeeded.
1 -- AUTOCOMMIT is on.
</pre></div>
    </div>
   </div>

  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.db2-autocommit-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="db2_connect.html" class="function" rel="rdfs-seeAlso">db2_connect()</a> - Returns a connection to a database</span></li>
    <li class="member"><span class="function"><a href="db2_pconnect.html" class="function" rel="rdfs-seeAlso">db2_pconnect()</a> - Returns a persistent connection to a database</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>